package com.reefe.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.reefe.entity.Result;
import com.reefe.pojo.TbContent;
import com.reefe.service.ContentService;
import com.reefe.utils.ResultUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created by xiao on 2018-03-07.
 */
@RestController
@RequestMapping("/content")
public class ContentController {

    @Reference(version = "1.0.0")
    private ContentService contentServiceImpl;

    @RequestMapping(value="/list/{cid}",method = RequestMethod.GET)
    public Map<String,Object> getContentByCid(@PathVariable("cid") Long cid){

        Map<String, Object> result = contentServiceImpl.getContentListByCid(cid);
        return result;
    }

    @RequestMapping(value="/del/{id}",method = RequestMethod.DELETE)
    public Result deleteContent(@PathVariable("id") Long id){
        int i = contentServiceImpl.deleteContent(id);
        return new ResultUtil<Object>().setData(null);
    }

    @RequestMapping(value="/add",method = RequestMethod.POST)
    public Result addContent(TbContent tbContent){
        int i = contentServiceImpl.addContent(tbContent);
        return new ResultUtil<Object>().setData(null);
    }

    @RequestMapping(value="/update",method = RequestMethod.POST)
    public Result updateContent(TbContent tbContent){
        int i = contentServiceImpl.updateContent(tbContent);
        return new ResultUtil<Object>().setData(null);
    }
}
